package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */

@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {


    @Autowired
    TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    TbBusinessMapper tbBusinessMapper;

    @Autowired
    private ISysDictDataService sysDictDataService;



    /**
     * 查询商机跟进记录列表
     */
    @Override
    public List<TbBusinessTrackRecord> getBusinessList(Long id) {
        List<TbBusinessTrackRecord> business = tbBusinessTrackRecordMapper.getBusiness(id);
        for (TbBusinessTrackRecord tbBusinessTrackRecord : business) {
            String[] split = tbBusinessTrackRecord.getKeyItems().split(",");
            List<String> keys = tbBusinessTrackRecord.getKeys();
            for (String s : split) {
                String s1 = sysDictDataService.selectDictLabel("communication_point", s);
                keys.add(s1);
            }
        }
        return business;
    }


    @Override
    public List<TbBusinessTrackRecord> selectTbBusinessTrackRecordList(Long id) {
        return tbBusinessTrackRecordMapper.selectTbBusinessTrackRecordListByBusinessId(id);
    }

    @Override
    public int insertTbBusinessTrackRecord(TbBusiness tbBusiness, TbBusinessTrackRecord tbBusinessTrackRecord) {
        tbBusinessMapper.updateTbBusiness(tbBusiness);
        return tbBusinessTrackRecordMapper.insertTbBusinessTrackRecord(tbBusinessTrackRecord);
    }
}
